<template>
	<view>
		<!-- <uni-sign-in ref="signIn"></uni-sign-in> -->
		<view style="display: flex;align-items: center; width: 100%;height: 350rpx;background-image: url('static/9.png') ;background-size: 100% 100%;">
			<view style="display: flex;align-items: center;">
				<view style="display: flex;justify-content: center;" @click="touxianggenggai">
					<image style="display: flex;height: 120rpx;width: 120rpx;border-radius: 50%;border: white solid 3rpx;margin:0 50rpx; " :src="src" mode="aspectFill"></image>
				</view>
				<view style="display: flex;justify-content: center;margin-top: 10rpx;font-size: 40rpx;font-weight: 500;color: white;">
					{{meiyi_name_tel.name}}
				</view>
			</view>
			
		</view>
		<view style="display: flex;font-size: 28rpx; background-color: black;color: white;padding: 10rpx;align-items: center;width: 700rpx;margin: -80rpx auto 0 auto;border-radius: 10rpx 10rpx 0 0;">
			<image style="width: 55rpx;margin:0 25rpx 0 15rpx;" src="../../static/dengji.gif" mode="widthFix"></image>
			美亦美拉官方旗舰店！
		</view>
		
		
		<!-- 菜单 -->
		<view style="display: flex;width: 95%; flex-direction:column;font-size: 25rpx; background-color: white; margin: 20rpx auto;border-radius: 20rpx;box-shadow: 2rpx 2rpx 5rpx 5rpx #eee;align-items: center;justify-content: center;">
			<view  style="width:95%;margin: 20rpx 10rpx;">
				<view style="display: flex;width: 700rpx;margin: 0 auto 0 auto;flex-wrap: wrap;justify-content: space-around;">
					<view v-for="item in caidanlists1" v-if="meiyi_userinfo.permission.indexOf(item.shenfen)!=-1" style="display: flex;flex-direction: column;justify-content: center;align-items: center;width:160rpx;margin:20rpx 0;font-size: 25rpx;" @click="tiaozhan(item.url)">
						<image style="width: 90rpx;height: 90rpx;" :src="item.pic" mode=""></image>
						<view style="display: flex;justify-content: center;margin-top:10rpx;">
							{{item.candan_name}}
						</view>
					</view>
					<!-- 下面是填位使用 -->
					<view v-if="(4-caidanshu % 4 >0 && caidanshu%4!=0)" style="display: flex;flex-direction: column;justify-content: center;align-items: center;width:160rpx;margin:20rpx 0" >
						<image style="width: 90rpx;height: 90rpx;" src="" mode=""></image>
						<view style="display: flex;justify-content: center;margin-top:10rpx;">
						</view>
					</view>
					<view v-if="(4-caidanshu % 4 >1 && caidanshu%4!=0)" style="display: flex;flex-direction: column;justify-content: center;align-items: center;width:160rpx;margin:20rpx 0" >
						<image style="width: 90rpx;height: 90rpx;" src="" mode=""></image>
						<view style="display: flex;justify-content: center;margin-top:10rpx;">
						</view>
					</view>
					<view v-if="(4-caidanshu % 4 >2 && caidanshu%4!=0)" style="display: flex;flex-direction: column;justify-content: center;align-items: center;width:160rpx;margin:20rpx 0" >
						<image style="width: 90rpx;height: 90rpx;" src="" mode=""></image>
						<view style="display: flex;justify-content: center;margin-top:10rpx;">
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 我的订单 -->
		<view style="display: flex;width: 95%; flex-direction:column;font-size: 25rpx; background-color: white; margin: 20rpx auto;border-radius: 20rpx;box-shadow: 2rpx 2rpx 5rpx 5rpx #eee;align-items: center;justify-content: center;">
			<view style="display: flex; width: 100%;border-bottom-style: solid;border-width: 3rpx;border-color: #eee;justify-content: space-between;align-items: center;">
				<view style="margin: 20rpx 0 0 50rpx;font-weight: bold;padding-bottom: 15rpx">
					我的订单
				</view>
				<view style="color: darkgrey;margin-right: 20rpx;">
					查看全部订单>
				</view>
			</view>
			<view  style="width:95%;margin: 10rpx 10rpx 20rpx 10rpx;">
				<view style="display: flex;width: 700rpx;margin: 0 auto 0 auto;flex-wrap: wrap;justify-content: space-around;">
					<view v-for="item in mydingdan" v-if="meiyi_userinfo.permission.indexOf(item.shenfen)!=-1" style="display: flex;flex-direction: column;justify-content: center;align-items: center;width:160rpx;margin:20rpx 0;" @click="tiaozhan(item.url)">
						<image style="width: 90rpx;height: 90rpx;" :src="item.pic" mode=""></image>
						<view style="display: flex;justify-content: center;margin-top:10rpx;">
							{{item.candan_name}}
						</view>
					</view>
					<!-- 下面是填位使用 -->
					<view v-if="(4-caidanshu % 4 >0 && caidanshu%4!=0)" style="display: flex;flex-direction: column;justify-content: center;align-items: center;width:160rpx;margin:20rpx 0" >
						<image style="width: 90rpx;height: 90rpx;" src="" mode=""></image>
						<view style="display: flex;justify-content: center;margin-top:10rpx;">
						</view>
					</view>
					<view v-if="(4-caidanshu % 4 >1 && caidanshu%4!=0)" style="display: flex;flex-direction: column;justify-content: center;align-items: center;width:160rpx;margin:20rpx 0" >
						<image style="width: 90rpx;height: 90rpx;" src="" mode=""></image>
						<view style="display: flex;justify-content: center;margin-top:10rpx;">
						</view>
					</view>
					<view v-if="(4-caidanshu % 4 >2 && caidanshu%4!=0)" style="display: flex;flex-direction: column;justify-content: center;align-items: center;width:160rpx;margin:20rpx 0" >
						<image style="width: 90rpx;height: 90rpx;" src="" mode=""></image>
						<view style="display: flex;justify-content: center;margin-top:10rpx;">
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<view v-for="item in caidanlists" v-if="meiyi_userinfo.permission.indexOf(item.quanxian)!=-1 || item.quanxian=='all'"  @click="tiaozhan(item.url)" style="display: flex;width: 85%;margin:20rpx auto 0 auto;box-shadow: 1px 1px 5px #c2c2c2;background-color: white;border-radius: 20rpx; flex-direction: row; justify-content: space-between;padding: 20rpx 30rpx;font-size: 26rpx;">
			<view class="">
				{{item.name}}
			</view>
			<uni-icons type="forward"></uni-icons>
		</view>
		
		<view @click="tuichu" style="display: flex;width: 40%;background-color: blue;color: white;border-radius: 20rpx;align-items: center;justify-content: center;padding: 20rpx;margin: 40rpx auto 20rpx auto;">
			退出登陆
		</view>
	</view>
</template>

<script>
	import {
		store,
		mutations
	} from '@/uni_modules/uni-id-pages/common/store.js'
	export default {
		data() {
			return {
				caidanshu:0,
				mydingdan:[
					{
						candan_name:"待付款",
						pic:"../../static/caidan/laoshifengcai.png",
						shenfen:"get_laoshilist",
						url:"/pages/fenxianghaibao/fenxianghaibao"
					},
					{
						candan_name:"待发货",
						pic:"../../static/caidan/genggaijilu.png",
						shenfen:"get_genggailist",
						url:"/pages/xiugaishuju/xiugaishuju"
					},
					{
						candan_name:"待收货",
						pic:"../../static/caidan/baokeliebiao.png",
						shenfen:"get_baokelist",
						url:"/pages/xueshenginfor/xueshenginfor"
					},
					{
						candan_name:"已完成",
						pic:"../../static/caidan/xinshengbaoke.png",
						shenfen:"update_baokelist",
						url:"/pages/xueshengluru/xueshengluru"
					}
				],
				caidanlists1:[
					{
						candan_name:"推广二维码",
						pic:"../../static/caidan/laoshifengcai.png",
						shenfen:"get_laoshilist",
						url:"/pages/fenxianghaibao/fenxianghaibao"
					},
					{
						candan_name:"优惠券",
						pic:"../../static/caidan/genggaijilu.png",
						shenfen:"get_genggailist",
						url:"/pages/xiugaishuju/xiugaishuju"
					},
					{
						candan_name:"充值余额",
						pic:"../../static/caidan/baokeliebiao.png",
						shenfen:"get_baokelist",
						url:"/pages/xueshenginfor/xueshenginfor"
					},
					{
						candan_name:"我的收益",
						pic:"../../static/caidan/xinshengbaoke.png",
						shenfen:"update_baokelist",
						url:"/pages/xueshengluru/xueshengluru"
					}
				],
				caidanlists:[
					{
						name:"我的资料",
						quanxian:"all",
						url:"/uni_modules/uni-id-pages/pages/userinfo/userinfo"
					},
					{
						name:"通知消息",
						quanxian:"xiugai_lunbotu",
						url:"/pages/notice/notice"
					},
					{
						name:"修改轮播图",
						quanxian:"xiugai_lunbotu",
						url:"/pages/banner/banner"
					},
					{
						name:"商品分类",
						quanxian:"all",	
						// quanxian:"add_kechengfenlei",	
						url:"/pages/goods_fenlei/goods_fenlei"
					},
					{
						name:"商品添加",
						quanxian:"all",
						url:"/pages/goods_add/goods_add"
					},
					{
						name:"商品参数",
						quanxian:"all",
						url:"/pages/goods_canshu/goods_canshu"
					},
					{
						name:"添加海报",
						quanxian:"add_shangpin",
						url:"/pages/addfenxianghaibao/addfenxianghaibao"
					},
					{
						name:"添加商品",
						quanxian:"add_shangpin",
						url:"/pages/shangpin_add/shangpin_add"
					},
					{
						name:"设置",
						quanxian:"all",
						url:""
					},
					{
						name:"技术支持",
						quanxian:"all",
						url:""
					},
					{
						name:"重置密码",
						quanxian:"all",
						url:"/uni_modules/uni-id-pages/pages/retrieve/retrieve"
					},
				],
				src:'',
				shu1:'',
				meiyi_userinfo:{
					permission:[]
				},
				meiyi_name_tel:[]
			}
		},
		computed: {
			hasLogin(){
				return store.hasLogin
			}
		},
		async onLoad() {
			this.meiyi_name_tel=await uni.getStorageSync('meiyi_name_tel')
			this.meiyi_userinfo=await uniCloud.getCurrentUserInfo()
			this.src=this.meiyi_name_tel.avatar?this.meiyi_name_tel.avatar:'../../static/uni-center/defaultAvatarUrl.png'
			this.shu1=this.meiyi_userinfo.uid
			
		},
		onShow() {
			
		},
		computed: {
		},
		methods: {
			//跳转
			tiaozhan(e){
				console.log(e);
				uni.navigateTo({
					url: e
				});
			},
			// 修改头像
			xiugai(){
				const db = uniCloud.database()
				let item=this.meiyi_userinfo
				item.zhaopian=this.src
				item._id=this.meiyi_userinfo._id
				delete item._id
				delete item.ss
				db.collection('userinfo').doc(this.shu1).update(item).then(e=>{
				})
				// 延时半秒执行代码
				setTimeout(() => {
					item._id=this.shu1
					uni.setStorageSync("meiyi_userinfo",item)
					console.log("item",item)
					console.log("shu1",this.shu1)
				}, 500)
			},
			touxianggenggai(){
				let that=this
				uni.chooseImage({
					count: 1,
					success(res) {
						if (res.tempFilePaths.length > 0) {
							let filePath = res.tempFilePaths[0]
							// callback方式
							uniCloud.uploadFile({
								filePath: filePath,
				        cloudPath: 'a.jpg',
				        onUploadProgress: function(progressEvent) {
				          console.log(progressEvent);
				          var percentCompleted = Math.round(
				            (progressEvent.loaded * 100) / progressEvent.total
				          );
								},
								success(e) {
									that.src=e.fileID
									that.xiugai()
								},
								fail() {},
								complete() {}
							});
							
						}
						
					}
				});
				

			},
			async tuichu(){
				await mutations.logout()
				// uniIdCo.logout()
				// uni.removeStorageSync('meiyi_userinfo')
				// uni.navigateTo({
				// 		url: "/pages/denglu/denglu"
				// })
			},
			toSettings() {
				uni.navigateTo({
					url: "/pages/ucenter/settings/settings"
				})
			},
			ucenterListClick(item) {
				if (!item.to && item.event) {
					this[item.event]();
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f8f8f8;
	}
</style>